﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;

namespace PeisongWeb.admin
{
    public partial class reportBusinessDetail : adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dt;
                if (Request.QueryString["ff"] != null)
                {
                    string ff = Request.QueryString["ff"].ToString();
                    if (ff == "0")
                        dt = getdata("0");
                    else
                    {
                        string  rbno = ff;
                        dt = DAL.reportBusiness.getDetailByRbNo(rbno);
                    }

                    if (!hasPermission("DC", 4))
                    {
                        ReportViewer1.LocalReport.ReportPath = "admin/reportBusinessDetailWithoutPrice.rdlc";
                    }

                    ReportDataSource rds = new ReportDataSource("reportBusiness_DataTable1", dt);
                    ReportViewer1.LocalReport.DataSources.Clear();

                    //ReportViewer1.LocalReport.GetDefaultPageSettings().PaperSize.Width = 241;
                    //ReportViewer1.LocalReport.GetDefaultPageSettings().PaperSize.Height = 140;

                    ReportParameter rb_No = new ReportParameter("rb_No", (ff == "0" ? "" : "提货单号:"+ff));
                    ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rb_No });
                    ReportViewer1.LocalReport.DataSources.Add(rds);
                    
                    ReportViewer1.LocalReport.Refresh();
                    if (dt.Rows.Count == 0)
                    {
                        ReportViewer1.Visible = false;
                        div_nodata.Visible = true;
                    }
                    else {
                        div_nodata.Visible = false;
                    }
                }
                else
                {
                    Library.Script.ClientMsgUrl("错误的参数。", "reportbusiness.aspx");
                }
            }
        }

        protected DataTable getdata(string flag)
        {
            return DAL.reportBusiness.create(logic.sysAdmin.AdminID, flag,DateTime.Now);
        }
    }
}
